from pydantic_settings import BaseSettings
from pathlib import Path

class Settings(BaseSettings):
    CHAT_API_KEY: str
    RETRIEVER_API_KEY: str
    BASE_URL: str = "https://qianfan.baidubce.com/v2"

    class Config:
        # 计算.env文件的绝对路径（假设它与main.py在同一目录）
        env_file = Path(__file__).parent / ".env"
        # env_file = "./.env"
        env_file_encoding = "utf-8"
        case_sensitive = True  # 区分大小写
        
# 确保 settings 对象在全局作用域内
settings = Settings()  # <-- 关键：在此处实例化并导出

# 调试输出（仅开发环境需要）
if __name__ == "__main__":
    try:
        print(f"加载配置文件:")
        s = Settings()
        print(f"配置加载成功: {s.model_dump()}")
    except Exception as e:
        print(f"配置加载失败: {e}")